package com.doitedu.doit30.hbase.client;

import com.doitedu.doit30.hbase.utils.HbaseUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.TableDescriptor;

/**
 * @Date 22.6.9
 * @Created by HANGGE
 * @Description
 *  删除表
 *  获取表信息
 */
public class _03TableOtherOperator {
    public static void main(String[] args) throws Exception {
        Connection connection = HbaseUtil.getHbaseConnection();
        Admin admin = HbaseUtil.getAdmin(connection);


        // 删除表
        /**
         * 1 判断表是否存在
         * 2 判断是否禁用
         * 3 删除
         */
    /*
        TableDescriptor descriptor = admin.getDescriptor(table);
        ColumnFamilyDescriptor[] cfs = descriptor.getColumnFamilies();
        for (ColumnFamilyDescriptor cf : cfs) {
        }*/

        TableName table = TableName.valueOf("tb_java");

        boolean isExists = admin.tableExists(table);
        if(isExists){  // 存在
            // 判断表是否是禁用
            boolean isDisabled = admin.isTableDisabled(table);
            if(isDisabled){
                admin.deleteTable(table);
            }else {
                // 禁用
                admin.disableTable(table);
                // 删除
                admin.deleteTable(table);
            }
        }
        admin.close();
       connection.close();


    }
}
